package fileHandler;

import entity.Word;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;
import java.util.Set;

public class PushSegmentedResult2File {
    /**
     * 将每首诗的分词结果写入文件中保存
     * @param wordList
     * @param filePath
     */
    public static void push(List<Word> wordList, String filePath) {
        try {
            FileOutputStream file_fos = new FileOutputStream(filePath,true);//设置为true, 追加模式
            OutputStreamWriter file_osw = new OutputStreamWriter(file_fos, "UTF-8");
            BufferedWriter file = new BufferedWriter(file_osw);

            for(Word word:wordList){
                file.write(word.getWord());
                file.write(" ");
            }
            file.newLine();

            file.close();
            file_osw.close();
            file_fos.close();

        } catch (IOException e) {
            System.out.println("Error:" + e.getMessage());
        }

    }
}
